package com.geez.bbl.util;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @author biniam.gebremichael
 * @since 6/27/12
 */
public class ParagraphBuilder {

    public static void main(String[] args) {
        File resourceFile = null;
        if (args.length > 0) {
            resourceFile = new File(args[0]);
        }

        List<String> contents = FileUtils.readFileToListOfLines(resourceFile);
        List<String> result = new ArrayList<String>();
        int book = 0;
        int chapter = 1;
        int vs = 1;
        String priviousLine = "";

        for (String content : contents) {
            String c = content.trim();
            if (c.isEmpty()) {
                continue;
            }
            if (c.indexOf("CHAPTER") == 0 || c.indexOf("PSALM") == 0) {
                chapter = Integer.valueOf(c.replace("CHAPTER ", "").replace("PSALM ", "").trim());
                if (chapter == 1) {
                    book++;
                    System.out.println(book + " " + priviousLine);
                }
            } else if (c.matches("^\\d.*")) {
                String[] line = c.split("\\s");
                vs = Integer.valueOf(line[0]);

                if (line[1].indexOf("#") == 0) {
                    String insert = String.format("%d,%d,%d,1", book, chapter, vs);
                    result.add(insert);
                    System.out.println("insert = " + insert);
                } else {
                    result.add(String.format("%d,%d,%d,0", book, chapter, vs));
                }

            }
            priviousLine = c;
        }
    }

}
